package com.example.wechat.enums;

import lombok.Data;

/**
 *
 * 支付状态：
 * NULL:代表没有该订单
 * PAYERROR：支付失败（仅付款码支付会返回）
 * SUCCESS：支付成功
 * USERPAYING：用户支付中（仅付款码支付会返回）
 * NOTPAY：未支付
 * REVOKED：已撤销（仅付款码支付会返回）
 * REFUND：转入退款
 * CLOSED：已关闭
 */

public enum PayStates {
    ERROR(null,null),
    NULL(null,"没有该订单"),
    PAYERROR("PAYERROR","支付失败"),
    SUCCESS("SUCCESS","支付成功"),
    USERPAYING("USERPAYING","用户支付中"),
    NOTPAY("NOTPAY","未支付"),
    REVOKED("REVOKED","已撤销"),
    REFUND("REVOKED","转入退款"),
    CLOSED("CLOSED","已关闭");
    private String tradeState;
    private String tradeStateDesc;
    PayStates(String tradeState,String tradeStateDesc){
        this.tradeState=tradeState;
        this.tradeStateDesc=tradeStateDesc;
//        switch (name){
//            case "PAYERROR": this.name="支付失败";break;
//            case "SUCCESS": this.name="支付成功";break;
//            case "USERPAYING": this.name="用户支付中";break;
//            case "NOTPAY": this.name="未支付";break;
//            case "REVOKED": this.name="已撤销";break;
//            case "REFUND": this.name="转入退款";break;
//            case "CLOSED": this.name="已关闭";break;
//        }
    }
    public static PayStates getPayStates(String tradeState){
        if(tradeState==null)
            return PayStates.NULL;
        switch (tradeState){
            case "PAYERROR": return PayStates.PAYERROR;
            case "SUCCESS": return PayStates.SUCCESS;
            case "USERPAYING": return PayStates.USERPAYING;
            case "NOTPAY": return PayStates.NOTPAY;
            case "REVOKED": return PayStates.REVOKED;
            case "REFUND": return PayStates.REFUND;
            case "CLOSED": return PayStates.CLOSED;
            default:
                return PayStates.ERROR;
        }
    }
    public boolean isERROR(){
        if(this.tradeStateDesc==null && this.tradeState==null)
            return true;
        else
            return false;
    }
    public String getTradeState() {
        return tradeState;
    }

    public String getTradeStateDesc() {
        return tradeStateDesc;
    }
}
